<?php

$uname   = $_POST['uname'];
$pwd = md5($_POST['pwd']);
$state = $_POST['state'];
@mysql_connect('localhost', 'root', 'root');
mysql_select_db('blog');
mysql_set_charset('utf8');
$sql = "insert into `homeusers` (`uname`,`pwd`,`state`) values ('$uname','$pwd','$state')";
$res = mysql_query($sql);

if ($res) {
    echo "<script>alert('添加成功');window.location.href='index.php'</script>";
} else {
    echo "<script>alert('添加失败');window.location.href='add.php'</script>";
}
